<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html>
<html:header title="入库单详情">

    <link rel="stylesheet" href="${baseUrl}css/public.css" media="all">

    <style type="text/css">

        .layui-table-view{
            margin: 0;
        }
    </style>

    <script>
        jQuery(function () {
            ajaxSelect("${baseUrl}settAccount/settAccount/listVo.action","settAccountId");
            $("#cancel").click(function () {
                closeSubIframe();
            });
        });

        layui.use(['form', 'table', 'laydate'], function () {
            let $ = layui.jquery,
                form = layui.form,
                table = layui.table,
                laydate = layui.laydate,
                util = layui.util;


            get("${baseUrl}house/houseIn/getVoById.action?id=${id}", function (res) {
                if (res.code == 1) {
                    $("#print").click(function () {
                        document.getElementById("printFrame").contentWindow.printPage(res.data);
                    });

                    if (res.data.close==1) {
                        showCloseImage();
                    }

                    let linkOrder = genLinOrder(res.data);
                    if (linkOrder.linkUnit != "") {
                        $("#linkUnit").html(linkOrder.linkUnit.name);
                    } else {
                        $("#linkUnit").html("无");
                    }

                    $("#typeName").html(linkOrder.typeName);
                    $("#linkNo").html(linkOrder.linkNo);
                    $("#linkNo").attr("linkDetailUrl",linkOrder.linkDetailUrl);
                    $("#linkNo").attr("linkDetailTitle",linkOrder.linkDetailTitle);

                    $("#linkNo").unbind().bind('click',function () {
                        openTab($(this).attr("linkDetailTitle"), $(this).attr("linkDetailUrl"));
                    });

                    $("#house").html(res.data.houseVo.store.name + ">" + res.data.houseVo.name);

                    $("#no").html(res.data.no);
                    $("#user").html(res.data.user.name);
                    $("#date").html(GMTToDate(res.data.date));


                    $("#deliveryOrg").html(res.data.deliveryOrg);
                    $("#deliveryNo").html(res.data.deliveryNo);
                    $("#deliveryAmt").html(getPrice(res.data.deliveryAmt));
                    $("#settAccount").html(res.data.settAccountVo.store.name + ">" + res.data.settAccountVo.name);

                    $("#remark").html(res.data.remark);

                    $("#makeUser").html(res.data.makeUser.name);
                    $("#makeTime").html(res.data.makeTime);

                    let list=[];
                    $.each(res.data.houseInGoodsVoList, function (i,d) {
                        let vo = d.goodsId==null? d.packetVo:d.goodsVo;
                        vo.goodsId = d.goodsId;
                        vo.number = d.number;
                        vo.unitId = d.unitId;
                        vo.remark = d.remark;
                        list.push(vo);
                    });

                    $.each(res.data.houseInPacketVoList, function (i,d) {
                        let vo = d;
                        vo.packetId = d.packetId;
                        vo.no = d.packetNo;
                        vo.name = d.packetName;
                        vo.number = d.number;
                        vo.unitId = d.unitId;
                        vo.remark = d.remark;
                        list.push(vo);
                    });

                    renderTable(list);
                }else {
                    tip("获取订单信息失败");
                }
            });
        });

        function renderTable(list) {
            layui.table.render({
                id: 'table',
                elem: '#table',
                data: list,
                totalRow:true,
                text: {
                    none: '未选择商品' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                },
                cols: [[
                    {type: 'numbers'},
                    {field: 'name', minWidth: 140, title: '名称/规格',style:"font-size:12px;",templet:"#nameBar"},
                    {field: 'no', width: 140, title: '商品编号', style: "font-size:12px;"},
                    {width: 120, title: '属性', style: "font-size:12px;", templet: function (d) {
                        return genAttr(d.attrNameVoList);
                    }},
                    {field:'number', width: 110, title: '数量',templet:'#numberBar'},
                    {width: 110, title: '序列号',templet: "#snNumberBar"},
                    {width: 120, title: '单位', style: "font-size:12px;", templet: function (d) {
                        return d.goodsId==null ? "": genUnitName(d.goodsUnitVoList,d.unitId);
                    }},
                    {field: 'remark', width: 120, title: '备注', style: "font-size:12px;"},

                ]],
                limit: Number.MAX_VALUE,
                done: function (res, curr, count) {
                    $(".packetName").unbind().bind('click',function () {
                        let index = $(this).parents('tr').data('index');
                        let tableData = layui.table.cache.table;
                        showPacketList(tableData[index].name, tableData[index].packetGoodsVoList);
                    });

                    $(".snNumberDiv").unbind().bind('click',function () {
                        let index = $(this).parents('tr').data('index');
                        let tableData = layui.table.cache.table;
                        showSnList(tableData[index].name, tableData[index].goodsSnList);
                    });

                    processTotalRow();

                    $(".numberDiv").mouseover(function () {
                        $(this).find(".snDiv").css("display","block");
                    }).mouseout(function () {
                        $(this).find(".snDiv").css("display","none");
                    })
                }
            });
        }


        function processTotalRow() {
            let number = 0;
            $.each(layui.table.cache.table, function (i,d) {
                number += parseInt(d.number);
            });
            setTotalRow("number",number);
            setTotalRow("0","合计");
        }

        //获取关联单结构体
        function genLinOrder(d) {
            let vo = {};
            if (d.type ==1) {
                vo = d.inGoodsVo;
                vo.linkUnit = d.inGoodsVo.provider;
                vo.typeName = '进货';
                vo.linkNo = d.inGoodsVo.no;
                vo.linkDetailUrl = "${baseUrl}inGoods/inGoodsDetail.action?id="+d.inGoodsVo.id;
                vo.linkDetailTitle = "进货单详情";
                return vo;
            }
            if (d.type ==2) {
                vo = d.refundVo;
                vo.linkUnit = d.refundVo.custom;
                vo.typeName = '销售退货';
                vo.linkNo = d.refundVo.no;
                vo.linkDetailUrl = "${baseUrl}sale/refundDetail.action?id="+d.refundVo.id;
                vo.linkDetailTitle = "销售退货单详情";
                return vo;
            }

            if (d.type ==3) {
                vo = d.goodsTransferVo;
                vo.linkUnit = "";
                vo.typeName = '调拨单';
                vo.linkNo = d.goodsTransferVo.no;
                vo.linkDetailUrl = "${baseUrl}house/goodsTransferDetail.action?id="+d.goodsTransferVo.id;
                vo.linkDetailTitle = "调拨单详情";
                return vo;
            }
            if (d.type ==4) {
                vo = d.borrowInVo;
                vo.linkUnit = d.borrowInVo.provider;
                vo.typeName = '借入单';
                vo.linkNo = d.borrowInVo.no;
                vo.linkDetailUrl = "${baseUrl}house/borrowInDetail.action?id="+d.borrowInVo.id;
                vo.linkDetailTitle = "借入单详情";
                return vo;
            }
            if (d.type ==5) {
                vo = d.borrowOutBackVo;
                vo.linkUnit = d.borrowOutBackVo.custom;
                vo.typeName = '借出归还';
                vo.linkNo = d.borrowOutBackVo.no;
                vo.linkDetailUrl = "${baseUrl}house/borrowOutBackDetail.action?id="+d.borrowOutBackVo.id;
                vo.linkDetailTitle = "借出归还单详情";
                return vo;
            }
        }
    </script>

</html:header>

<iframe id="printFrame" style="width:0px;height:0px" src="${baseUrl}print/houseInPrint.action" frameborder="0"></iframe>
<body>
<div class="layui-inline" style="margin-bottom: 20px;">
    <a class="layui-btn" id="print">打印</a>
    <a class="layui-btn layui-btn-primary" id="cancel">取消</a>
</div>

<div class="layuimini-container">
    <div class="layuimini-main">
        <html:closeOrderImage/>
        <h2 class="tableBeforeTitle">入库单</h2>
        <div style="height: 4px;background-color: #bbbbbb;width: 100%;margin: 20px 0 2px 0;"></div>
        <div style="height: 1px;width: 100%;background-color: #dddddd;margin-bottom: 10px;"></div>
        <div style="height: 10px;"></div>

        <form class="layui-form" action="" lay-filter="form">
            <input type="hidden" name="id" value="${id}">
            <div class="layui-inline" style="margin:0 20px 10px 0;">
                <div>
                    <span style="color: #aaaaaa">编号：</span>
                    <span id="no"></span>
                </div>
            </div>


            <div class="layui-inline" style="margin:0 20px 10px 0;">
                <div>
                    <span style="color: #aaaaaa">关联业务：</span>
                    <span id="typeName"></span>
                </div>
            </div>

            <div class="layui-inline" style="margin:0 20px 10px 0;">
                <div>
                    <span style="color: #aaaaaa">关联单号：</span>
                    <a href="javascript:;" id="linkNo"></a>
                </div>
            </div>


            <div class="layui-inline" style="margin:0 20px 10px 0;">
                <div>
                    <span style="color: #aaaaaa">往来单位：</span>
                    <span id="linkUnit"></span>
                </div>
            </div>

            <div class="layui-inline" style="margin:0 20px 10px 0;">
                <div>
                    <span style="color: #aaaaaa">入库仓库：</span>
                    <span id="house"></span>
                </div>
            </div>

            <div class="layui-inline" style="margin:0 20px 10px 0;">
                <div>
                    <span style="color: #aaaaaa">经手人：</span>
                    <span id="user"></span>
                </div>
            </div>

            <div class="layui-inline" style="margin:0 20px 10px 0;">
                <div>
                    <span style="color: #aaaaaa">业务日期：</span>
                    <span id="date"></span>
                </div>
            </div>

            <div>
                <div class="layui-inline" style="margin:0 20px 10px 0;">
                    <div>
                        <span style="color: #aaaaaa">物流公司：</span>
                        <span id="deliveryOrg"></span>
                    </div>
                </div>
                <div class="layui-inline" style="margin:0 20px 10px 0;">
                    <div>
                        <span style="color: #aaaaaa">物流单号：</span>
                        <span id="deliveryNo"></span>
                    </div>
                </div>
                <div class="layui-inline" style="margin:0 20px 10px 0;">
                    <div>
                        <span style="color: #aaaaaa">支付运费：</span>
                        <span id="deliveryAmt"></span>
                    </div>
                </div>

                <div class="layui-inline" style="margin:0 20px 10px 0;">
                    <div>
                        <span style="color: #aaaaaa">支付账户：</span>
                        <span id="settAccount"></span>
                    </div>
                </div>
            </div>

            <div style="height: 20px;"></div>
            <table class="layui-hide" id="table" lay-filter="table" lay-size="sm"></table>
            <table class="layui-table" style="margin: -1px 0 0 0;">
                <tbody>
                <tr>
                    <td>
                        <span style="color: #aaaaaa;padding-left: 20px;">备注：</span><span id="remark"></span>
                    </td>
                </tr>
                </tbody>
            </table>

            <hr>

            <span style="color: #aaaaaa;">制单人：</span><span id="makeUser"></span>
            <span style="color: #aaaaaa;padding-left: 20px;">制单时间：</span><span id="makeTime"></span>
        </form>
    </div>


    <script type="text/html" id="nameBar">
        {{#  if(d.goodsId==null){ }}
        <div class="packetName">
            {{d.name}}
        </div>
        {{#  }else{ }}
        {{genGoodsName(d.name,d.norms)}}
        {{#  } }}
    </script>

    <script type="text/html" id="numberBar" >
        <span class="number">{{ getNumber(d.number) }}</span>
        {{# if(d.sn==true){ }}
        <span class="numberSn">sn</span>
        {{# } }}
    </script>

    <script type="text/html" id="snNumberBar" >
        {{# if(d.sn==true){ }}
        {{# if(d.goodsSnList!=undefined && d.goodsSnList.length > 0){ }}
        <div class="snNumberDiv">{{d.goodsSnList.length}}个</div>
        {{# } }}
        {{# } }}
    </script>
</div>

</body>
<html:packetListDialog/>
<html:snListDialog/>
<html:loading/>
</html>